#!/bin/bash

# Copyright 2019 Mobvoi Inc. All Rights Reserved.

#export PYTHONPATH=/home/work/conda/envs/speechbrain/lib/python3.8/site-packages:$PYTHONPATH
#export PATH=/home/work/conda/envs/speechbrain/bin:$PATH
. ./path.sh || exit 1;

export CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7"

export NCCL_DEBUG=INFO
stage=5 # start from 0 if you need to start from data preparation
stop_stage=5

num_nodes=1

node_rank=0
data=data

nj=16
dict=./dict

train_set=train
dev=dev

train_config=./train.yaml
dir=exp/output

data_type=shard
testset=data/emo  #"data/testset/robot_cuishou_20230103 data/testset/robot_cuishou_20230104 data/testset/robot_cuishou_20230105 data/testset/robot_dianxiao_20230103 data/testset/robot_dianxiao_20230104 data/testset/robot_dianxiao_20230105 data/testset/robot_xinshen_20230103 data/testset/robot_xinshen_20230104 data/testset/robot_xinshen_20230105"
#test_data_path=/home/work_nfs10/pkchen/workspace/text2token/cosyvoice_style/data/emodata.list
test_data_path=/mnt/sfs/asr/update_data/asr_chat_znlin_2025-1-24/shards_list.txt
average_checkpoint=true
decode_checkpoint=$dir/final.pt
average_num=10
max_epoch=50
average_checkpoint=false
decode_checkpoint=/home/work_nfs10/pkchen/workspace/text2token/cosyvoice_style/exp/25hz_lre4/0.pt
llm_path=/mnt/sfs/asr/ckpt/cosyvoice1/llm.pt
decode_modes="attention_rescoring"
batch_size=1
thread_index=0
gpu_id=3
dataname=

. ./parse_options.sh || exit 1;


if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then
  decoding_chunk_size=
  ctc_weight=0.5
  reverse_weight=0.0
  for mode in ${decode_modes}; do
  {
      test_dir=$dir/$test/$mode/$(basename $decode_checkpoint)
      mkdir -p $test_dir
      python3 wenet/bin/recognize.py --gpu $gpu_id \
        --mode $mode \
        --config $train_config \
        --data_type $data_type \
        --test_data $test_data_path \
        --checkpoint $decode_checkpoint \
        --beam_size 10 \
        --batch_size $batch_size \
        --penalty 0.0 \
        --dict $dict \
        --ctc_weight $ctc_weight \
        --reverse_weight $reverse_weight \
        --result_file $test_dir/${dataname}_text_gpu_id_${gpu_id}_thread_index_$thread_index.scp \
        --llm_path $llm_path \
        ${decoding_chunk_size:+--decoding_chunk_size $decoding_chunk_size}
  }
  done
  wait
#  grep Overall $dir/data/testset/*/*/$(basename $decode_checkpoint)/wer
fi
